package Controller;

/**
 * Thread class for auto save execution 
 * @author Vincent Francolin
 * @version 1.0 : creation
 */
public final class AutoSave implements Runnable {
	private ContactController data;
	private boolean autoSaveActivated;
	private int waitingTime;
	
	/**
	 * default constructor
	 * @param data the main controller containing the data to save
	 */
	public AutoSave(ContactController data) {
		super();
		this.data = data;
		autoSaveActivated = true;
		waitingTime = 1000 * 60;
	}
	
	/**
	 * constructor with chosen sleeping time
	 * @param data the main controller containing the data to save
	 * @param wait time to wait between two save
	 */
	public AutoSave(ContactController data,int wait) {
		super();
		this.data = data;
		autoSaveActivated = true;
		waitingTime = wait;
	}



	@Override
	public void run() {
		// TODO Auto-generated method stub
		while(autoSaveActivated){
			data.saveContacts();
			data.saveGroups();
			try {
				Thread.sleep(waitingTime);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
